﻿using System.Collections.Generic;
namespace Windy.OpenLink.Contracts
{
    public class Network : INetwork
    {
        protected Dictionary<string, IHost> HostList;

        #region INetwork Members

        public IHost GetHost(string address)
        {
            IHost result;
            bool exist = HostList.TryGetValue(address, out result);

            return exist ? result : null;
        }

        public bool HostExist(string address)
        {
            return HostList.ContainsKey(address);
        }

        #endregion
    }

    public interface INetwork
    {
        IHost GetHost(string address);

        bool HostExist(string address);
    }

    public static class INetworkExtension
    {
        public static THost GetHost<THost>(this INetwork network, string address)
            where THost : class , IHost
        {
            return network.GetHost(address) as THost;
        }
    }
}